assume cs:code,ss:stack
stack segment
 db 128 dup (0)
stack ends
;===============install new int9
code segment 
start:  mov ax,code
        mov ds,ax
        mov si,offset newint9
       	mov ax,0
       	mov es,ax
       	mov di,204h
 
       	mov cx,offset newint9_end-offset newint9
       	cld
       	rep movsb
 
	push es:[9*4]
	pop es:[200h]
	push es:[9*4+2]
	pop es:[202h]
 
       	cli
       	mov word ptr es:[9*4],204h
       	mov word ptr es:[9*4+2],0
       	sti
 ;-------------------------tset newint9       
        ;call delay        ; the delay time is for test the program newint9
        
	cli
        push es:[200h]
        pop es:[9*4]
        push es:[9*4+2]
        pop es:[202h]
        sti
 
       	mov ax,4c00h
       	int 21h
 
delay:  push ax
        push dx
        mov dx,300h           
       	mov ax,0
delays: sub ax,1                
        sbb dx,0                
        cmp ax,0
        jne delays
	cmp dx,0
        jne delays
        pop dx
        pop ax
        ret
;============================set newint9 sub table
 newint9:jmp short set
  table dw offset sub1 - offset newint9 + 204h
        dw offset sub2 - offset newint9 + 204h
       	dw offset sub3 - offset newint9 + 204h
       	dw offset sub4 - offset newint9 + 204h
 
   set:  push ax
         push bx
	 push cx
 
       	 in al,60h
       	 pushf
       	 call dword ptr cs:[200h]
         
	 sub al,80h       ;(al)=(通码-81h)
	 mov ah,al
	 mov al,2
       	 cmp ah,3
       	 ja sret
        cmp ah,0
        jb sret
       	mov bl,ah
       	mov bh,0
       	add bx,bx
       	call word ptr table[bx]
 
   sret: 
	 pop cx
	 pop bx
	 pop ax
	 iret
;========================Subroutine 
sub1:   push bx
        push cx
        push es
 
        mov bx,0b800h
        mov es,bx
        mov bx,0
        mov cx,2000
sub1s:  mov byte ptr es:[bx],' '
        add bx,2
       	loop sub1s
 
       	pop es
       	pop cx
       	pop bx
       	ret
;------------------------
sub2:   push bx
        push cx
       	push es
 
       	mov bx,0b800h
       	mov es,bx
       	mov bx,1
       	mov cx,2000
sub2s:  and byte ptr es:[bx],11111000b
        or es:[bx],al
       	add bx,2
       	loop sub2s
 
       	pop es
       	pop cx
       	pop bx
       	ret
;----------------------
sub3:   push bx
        push cx
       	push es
 
       	mov cl,4
       	shl al,cl
       	mov bx,0b800h
       	mov es,bx
       	mov bx,1
       	mov cx,2000
sub3s:  and byte ptr es:[bx],10001111b
        or es:[bx],al
       	add bx,2
       	loop sub3s
 
       	pop es
       	pop cx
       	pop bx 
       	ret
;-----------------------
sub4:   push cx
       	push es
       	push ds
       	push si
       	push di
 
       	mov si,0b800h
       	mov es,si
       	mov ds,si
       	mov si,160
       	mov di,0
        cld
       	mov cx,24
sub4s:  push cx
        mov cx,80
       	rep movsw 
       	pop cx
       	loop sub4s
 
       	mov cx,80
       	mov si,0
sub4s1: mov byte ptr es:[160*24+si],' '
        add si,2
       	loop sub4s1
       
       	pop di
       	pop si
       	pop ds
       	pop es
       	pop cx
        ret
 
newint9_end: nop
 
code ends
end start
